// src/providers/LanguageProvider.tsx
import { useEffect } from 'react';
import { useSelector } from 'react-redux';
import { selectCurrentLanguage } from '../features/language/languageSlice';
import { RootState } from '../app/store';
import i18n from '../i18n/config'; // 你的 i18n 配置文件

const LanguageProvider = ({ children }: { children: React.ReactNode }) => {
    const currentLanguage = useSelector((state: RootState) => selectCurrentLanguage(state));

    useEffect(() => {
        // 当语言变化时，更新 i18n
        i18n.changeLanguage(currentLanguage);
    }, [currentLanguage]);

    return <>{children}</>;
};

export default LanguageProvider;